package com.example.test.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.test.entity.PrintTemplates;
import com.example.test.entity.TempItems;
import com.example.test.mapper.LodopMapper;
import com.example.test.mapper.StyleMapper;
import com.example.test.mapper.TempItemsMapper;
import com.example.test.mapper.TempsMapper;
import com.example.test.service.LodopService;
import com.example.test.service.TempService;
import com.example.test.vo.LodopVO;
import com.example.test.vo.PrintTemplatesVO;
import com.example.test.vo.TempItemsVO;
import com.example.test.vo.TempStyleVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@CrossOrigin(origins = {"http://localhost:8084","http://localhost:8080"})
@RestController
@RequestMapping("/test")
public class TempController {
    @Autowired
    private TempService tempService;
    @Autowired
    private LodopService lodopService;

    @PostMapping("save")
    public void saveTemp(@RequestBody List<PrintTemplatesVO> tempList) {
        tempService.save(tempList);
    }

    @GetMapping("listAll")
    public List<PrintTemplatesVO> listAll() {
        return tempService.listAll();
    }

    @PostMapping("/add")
    public void add(@RequestBody HashMap map) {
        String detail = map.get("detail").toString();
      System.out.println("============");
      System.out.println(detail);
        lodopService.add(detail);
    }

    @GetMapping("/del/{id}")
    public void del(@PathVariable("id") String idT) {
      Long id = Long.valueOf(idT);
      System.out.println(id);
      lodopService.del(id);

    }

    @GetMapping("/getAll")
    public String getAll() {
        List<LodopVO> list = lodopService.getAll();

        String jsonString = JSONObject.toJSONString(list);
        return jsonString;
    }
    @PostMapping("/edit")
    public void edit(@RequestBody LodopVO lodopVO) {
      System.out.println(lodopVO);
      lodopService.edit(lodopVO);
    }
}
